<template>
	<view class="page">
		<view class="list">
			<view class="item">
				<text class="key">姓名</text>
				<text class="value">{{name}}</text>
			</view>
			<view class="item">
				<text class="key">联系号码</text>
				<text class="value">{{account}}</text>
			</view>
			<view class="item">
				<text class="key">邮箱</text>
				<text class="value">{{email}}</text>
			</view>
			<view class="item">
				<text class="key">所在组织</text>
				<text class="value">{{organization}}</text>
			</view>
			<view class="item">
				<text class="key">任职岗位</text>
				<text class="value">{{post}}</text>
			</view>
		</view>
		<uni-section title="日报记录" type="line" style="margin-bottom: 3px;">
			<view class="textarea">
				<textarea 
					v-model="txt" 
					:maxlength="500" 
					placeholder-style="color:#ffffff" 
					placeholder="请输入日常工作记录........"/>
			</view>
		</uni-section>
		<button class="save-btn" @tap="save">提 交</button>
	</view>
</template>

<script>
export default {
		data() {
			return {
				//姓名
				name:'',
				//联系号码
				account:'',
				//邮箱
				email:'',
				//所在组织
				organization:'',
				//任职岗位
				post:'',
				//日报内容
				txt:''
			}
		},
		onLoad() {
			let that= this;
			//加载初始化用户相关信息
			that.loadInitUser(that);
		},
		methods: {
			 bindTextAreaBlur: function (e) {
				 this.txt = e.detail.value;
			},
			//加载初始化用户信息
			loadInitUser:function(ref){
					ref.ajax(ref.url.getuserinfo, "POST", null, function(resp) {
					let data = resp.data;
					let user = data.userinfo.user;
					let roles = data.userinfo.roles;
					if(!user.isRegistration){
						uni.showToast({
							title:"未登记",
							icon:'error'
						});
						setTimeout(function(){
							uni.switchTab({
								url:'../index/index'
							})
						},1000)
					}
					let message = "未填写";
					// 姓名
					if(user.name==null){
						ref.name = "新员工"
					}else{
						ref.name = user.name;
					}
					// 账号
					if(user.account==null){
						ref.account = message
					}else{
						ref.account = user.account
					}
					// 电子邮件
					if(user.email==null){
						ref.email = message
					}else{
						ref.email = user.email
					}
					// 当前所在组织
					if(user.organization==null){
						ref.organization = message
					}else{
						ref.organization = user.organization.name
					}
					//当前所在岗位
					if(user.job==null){
						ref.post = message
					}else{
						ref.post = user.job.name
					}
				});
			},
			//提交日报
			save(){
				let that = this;
				uni.showModal({
					title: '提示',
					content: '是否提交该日报内容',
					success: function(e) {
						if(e.confirm){
							that.ajax(that.url.setWorkDaily,'POST',{
								content:that.txt
							},function(resp){
								let data = resp.data
								if(data.code===20000){
									uni.showToast({
										icon: 'success',
										title: data.msg,
									});
									setTimeout(function(){
										uni.redirectTo({
											url:'../work_daily_list/work_daily_list'
										})
									},1000)
								}
							});
						}
					}
				});
			},
			
		}
	}
</script>

<style lang="less">
	@import url('work_daily.less');
</style>
